package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;

import client.ClientRSAConnection;
import client.ClientSSLConnection;
import client.ClientSSLResult;
import client.ConnectionData;

public class Reiter2ButtonListener implements ActionListener {

	ConnectionData clientData;
	MainFrame frame;

	public Reiter2ButtonListener(ConnectionData clientData, MainFrame frame) {
		this.clientData = clientData;
		this.frame = frame;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (arg0.getSource() instanceof JButton) {
			JButton button = (JButton) arg0.getSource();

			if (button.getText().equals("Registrieren")) {
				ClientSSLConnection sslConn = new ClientSSLConnection();
				ClientSSLResult result = sslConn.register(
						frame.reiter2HostField.getIP(),
						frame.reiter2UsernameField.getText(),
						ClientRSAConnection.getClientRSAKeyPair());
				clientData.key.serverPublicKey = result.pubKey;

				ConnectionData.addKey(frame.reiter2HostField.getIP(),
						clientData.key.serverPublicKey);

				JOptionPane.showMessageDialog(frame, "Passwort: "
						+ result.passwort);

			}
		}
	}

}
